package com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;

import com.tjsinfo.tjsoa.Dao.ISpringDao;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.MainType;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.SubTypeInfo;

public class TWenTypeBO  implements IWenTypeBO{
	private ISpringDao springDao;
	
	public ISpringDao getSpringDao() {
		return springDao;
	}

	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}


/**
 * 获取一级文种列表
 */
	public List<MainType> selectMainType() {
		
		StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_maintype");
		List<MainType> list = new ArrayList<MainType>();
		list = springDao.querySQL(sql.toString(), new Object[]{}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				MainType mainType = new MainType();
				mainType.setId(arg0.getInt("id"));
				mainType.setMainType(arg0.getString("maintype"));
				return mainType;
			}
			
		});
		
		return list;
	}

/**
 * 根据一级文种查询相对应的二级文种
 */
	
	public List<SubTypeInfo> selectSubType(Integer maintypeid) {
		StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_doctype WHERE maintypeId = ?");
		List<SubTypeInfo> list = new ArrayList<SubTypeInfo>();
		list = springDao.querySQL(sql.toString(), new Object[]{maintypeid}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				SubTypeInfo subTypeInfo = new SubTypeInfo();
				subTypeInfo.setId(arg0.getInt("id"));
				subTypeInfo.setTempList(arg0.getInt("templist"));
				subTypeInfo.setTempName(arg0.getString("tempname"));
				subTypeInfo.setTypeName(arg0.getString("typename"));
				return subTypeInfo;
			}
			
		});
		
		return list;

	}
/**
 * 根据一级文种id获取该一级文种信息
 */
	public List<MainType> selectMainTypeById(Integer id) {
		StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_maintype WHERE id = ?");
		List<MainType> list = new ArrayList<MainType>();
		list = springDao.querySQL(sql.toString(), new Object[]{id}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				MainType mainType = new MainType();
				mainType.setId(arg0.getInt("id"));
				mainType.setMainType(arg0.getString("maintype"));
				mainType.setItemType(arg0.getInt("itemtype"));
				return mainType;
			}
			
		});
		
		return list;
	}
/**
 * 根据二级文种id获取改二级文种信息
 */
	public List<SubTypeInfo> selectSubTypeById(Integer id) {
		StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_doctype WHERE id = ?");
		List<SubTypeInfo> list = new ArrayList<SubTypeInfo>();
		list = springDao.querySQL(sql.toString(), new Object[]{id}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				SubTypeInfo subTypeInfo = new SubTypeInfo();
				subTypeInfo.setId(arg0.getInt("id"));
				subTypeInfo.setTempList(arg0.getInt("templist"));
				subTypeInfo.setTempName(arg0.getString("tempname"));
				subTypeInfo.setTypeName(arg0.getString("typename"));
				subTypeInfo.setWenhaotype(arg0.getString("wenhaotype"));
				return subTypeInfo;
			}
			
		});
		
		return list;
}
	/**
	 * 根据二级文种name获取改二级文种信息
	 */
		public List<SubTypeInfo> selectSubTypeByName(String name) {
			StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_doctype WHERE typename = ?");
			List<SubTypeInfo> list = new ArrayList<SubTypeInfo>();
			list = springDao.querySQL(sql.toString(), new Object[]{name}, new RowMapper(){

				public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
					// TODO Auto-generated method stub
					SubTypeInfo subTypeInfo = new SubTypeInfo();
					subTypeInfo.setId(arg0.getInt("id"));
					subTypeInfo.setTempList(arg0.getInt("templist"));
					subTypeInfo.setTempName(arg0.getString("tempname"));
					subTypeInfo.setTypeName(arg0.getString("typename"));
					subTypeInfo.setWenhaotype(arg0.getString("wenhaotype"));
					return subTypeInfo;
				}
				
			});
			
			return list;

		}	

/**
 * 获取所有二级文种	
 */
	public List<SubTypeInfo> selectSubTypeAll() {
		StringBuffer sql = new StringBuffer("SELECT * FROM dbo.t_system_doctype");
		List<SubTypeInfo> list = new ArrayList<SubTypeInfo>();
		list = springDao.querySQL(sql.toString(), new Object[]{}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				SubTypeInfo subTypeInfo = new SubTypeInfo();
				subTypeInfo.setId(arg0.getInt("id"));
				subTypeInfo.setTypeName(arg0.getString("typename"));
				return subTypeInfo;
			}
			
		});
		return list;
	}

/**
 * 根据itemType，查找二级文种，区分行政、党委、纪、工、团
 */
	public List<SubTypeInfo> selectSubTypeByItem(Integer itemType) {
		StringBuffer sql = new StringBuffer("SELECT st.id, st.typename FROM dbo.t_system_doctype as st inner join dbo.t_system_maintype as mt on st.maintypeId=mt.id where mt.itemtype=? ");
		List<SubTypeInfo> list = new ArrayList<SubTypeInfo>();
		list = springDao.querySQL(sql.toString(), new Object[]{itemType}, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				SubTypeInfo subTypeInfo = new SubTypeInfo();
				subTypeInfo.setId(arg0.getInt("id"));
				subTypeInfo.setTypeName(arg0.getString("typename"));
				return subTypeInfo;
			}
			
		});
		return list;
}

}
